<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
</head>
<title>任务价值录制</title>
<style>
    .layui-form-select dl dd, .layui-form-select dl dt {
        padding: 4px 10px;
    }
</style>
<div class="lay-box">
    <form class="layui-form" action="" style="margin-top: 10px">

        <#--<div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">结束时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="end" placeholder="请选择时间">
            </div>
        </div>-->
        <#if fishMark==1>
            <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
                <select name="appId" id="appId" lay-verify="" style="width: 300px">
                    <option value="1">兼职咸鱼</option>
                    <option value="2">糯米狗</option>
                    <option value="3">豆豆</option>
                    <option value="4">许愿猫</option>
                    <option value="5">大象兼职</option>
                    <option value="6">果果赚钱</option>
                </select>

            </div>
        </#if>

        <div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">起始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="star" placeholder="请选择时间">
            </div>
        </div>
        <div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">结束时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="end" placeholder="请选择时间">
            </div>
        </div>



        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">

                <select name="sdkKey" id="sdkKey" lay-verify="" style="width: 300px">
                 <option value="">数据源</option>
                 <#list item as list>
                        <option value="${list.sdkKey}">${list.taskName}</option>
                </#list>
            </select>

        </div>

<#--        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">

            <select name="appStore" id="appStore" lay-verify="" style="width: 300px">
                <option value="">分渠到</option>
                <option value="all">汇总渠道</option>
                <#list appStoreList as list>
                    <option value="${list.code}">${list.name}</option>
                </#list>
            </select>

        </div>-->

        <div class="layui-form-item" style="width: 500px;display: inline-block;margin: 0 0 8px 20px;">
            <div class="layui-input-block">
                <select name="appStore" id="appStore" multiple="multiple" lay-filter="test">
                    <option value="">分渠到</option>
                    <option value="all">汇总渠道</option>
                    <#list appStoreList as list>
                        <option value="${list.code}">${list.name}</option>
                    </#list>
                </select>
            </div>
        </div>

    </form>
    <button class="layui-btn" onclick="add()" style="float: left;margin-left:20px">
         添加数据
    </button>
    <span onclick="search()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">查询</span>

    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>

<style>
    .lay-box {
        padding: 8px 12px;
    }

    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }
</style>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{
           d.enable== 1 ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    var category=2;

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'
            , format: 'yyyyMMdd'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'
            , format: 'yyyyMMdd'
        });
    });


    function lastCheck(){
        var last = $("#last").val();
        $.ajax({
            url: "/sys/cencesearnday/lastCheck",
            type: 'post',
            data: {date: last},
            async: false,
            dataType: "json",
            success: function (arg) {
                if (arg) {
                    layer.msg(arg.message);
                    search();
                } else {
                    layer.msg(arg.message);
                }
            }
        });
    }
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'
            , format: 'yyyyMMdd'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'
            , format: 'yyyyMMdd'
        });
        laydate.render({
            elem: '#last'
            , type: 'date'
            ,format: 'yyyy-MM-dd'
        });
    });
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var tableIns;
    var ids = "";
    var form;
    var table = "task_worth_record";
    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        form.render();
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/sys/taskworthrecord/page'

            , done: function(res, curr, count){
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            },
            method: 'POST'
            ,
            where: {
                //查询条件
               //  sdkKey: $("#sdkKey").val(),
               //  appId : $("#appId").val()
            }
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {type: 'checkbox', field: 'id'}
                ,{
                field: 'appid',
                title: '应用',
                width: 120,
                align: 'center',
                sort: true,templet: function (data) {
                        if(data.appid==1){
                            return '咸鱼';
                        }else if(data.appid==2){
                            return '糯米狗';
                        }else if(data.appid==3){
                            return '豆豆';
                        }else if(data.appid==4){
                            return '许愿猫';
                        }else if(data.appid==5){
                            return '大象兼职';
                        }else if(data.appid==5){
                            return '果果赚钱';
                        }else{
                            return '-';
                        }
                    }
        }
                , {
                    field: 'time',
                    title: '日期',
                    width: 110,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        if(data.time<0){
                            return '统计';
                        }else {
                            return data.time;
                        }
                    }
                }
                , {
                    field: 'sdkKey',
                    title: '数据源',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'appStore',
                    title: '渠道',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'show',
                    title: '展示',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'click',
                    title: '点击',
                    width: 110,
                    align: 'center',
                    sort: true
                }

                , {
                    field: 'award',
                    title: '收益',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'cpm',
                    title: 'cpm',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'finishNum',
                    title: '任务人数',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'taskFinishNum',
                    title: '任务数',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'taskWorth',
                    title: '任务价值',
                    width: 110,
                    align: 'center',
                    sort: true
                }

                , {
                    field: 'clickWorth',
                    title: '点击价值',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                // , {
                //     field: 'type',
                //     title: '1总计0分渠道',
                //     width: 150,
                //     align: 'center',
                //     sort: true
                // }
                , {
                    field: 'taskNumEvery',
                    title: '人均任务数',
                    width: 110,
                    align: 'center',
                    sort: true
                }

                //, {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150, align: 'center'}
                , {fixed: 'right', title: '操作',  width: 150, align: 'center',
                    templet: function (data) {
                        if(data.appStore=="all"){
                            return "";
                        }else{
                            return "    <a class=\"layui-btn layui-btn layui-btn-xs\" lay-event=\"edit\">编辑</a>\n" +
                                "    <a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"del\">删除</a>";
                        }
                    }}

            ]]
            ,
            page: true
        });

        form.on('switch(sexDemo)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, 1);
            } else {
                commonenable(this.value, 0);
            }

        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/sys/taskworthrecord/delete",
                    type: 'post',
                    data: {"id": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer_show("修改", "/sys/taskworthrecord/editPage?id=" + data.id, "1000", "650");
                parent.search();
            }
        });
    });

    function search() {
        var star = $("#star").val();
        var end = $("#end").val();
       var sdkKey = $("#sdkKey").val();
       var appId = $("#appId").val();
       var appStore = $("#appStore").val();
       console.log(appStore);
        tableIns.reload('dataTableId', {
            where: {appId:appId,sdkKey:sdkKey,appStore:JSON.stringify(appStore),star: star, end: end},
            page: {
                curr: 1
            }
        });
    }


    function add() {
        layer_show("新增", "/sys/taskworthrecord/add", "1000", "600");
    }

    function showmsg(msg) {
        layer.msg(msg)
    }

    function commonenable(id, status) {
        $.ajax({
            url: "/common/commonSwitch",
            type: 'post',
            data: {"table": table, "id": id, "status": status, "feild": "has_deleted"},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }


</script>
<script type="text/javascript">
    layui.use(['multiSelect'],function() {
        var $ = layui.jquery,form = layui.form,multiSelect = layui.multiSelect;
        $('#get-val').click(function() {
            var vals = [],
                texts = [];
            $('select[multiple] option:selected').each(function() {
                vals.push($(this).val());
                texts.push($(this).text());
            })
            console.dir(vals);
            console.dir(texts);
        })
        form.on('select(test)',function(data){
            console.dir(data);
        })
    });
</script>
<script>



    layui.define("form", function(exports) {
        var MOD_NAME = "multiSelect",
            o = layui.jquery,
            form = layui.form,
            selected_vals = [],
            multiSelect = function() {};

        multiSelect.prototype.init = function() {
            var ts = this;
            o('select[multiple]').each(function(idx, item) {
                var t = o(this),
                    selds = [];
                t.find('option:selected').each(function() {
                    selds.push(o(this).val());
                })
                t.next().addClass('multi').find('.layui-select-title').click(function() {
                    selected_vals[idx] && o(this).find('input').val(selected_vals[idx].join(','));
                }).next().find('dd').each(function() {
                    var dt = o(this),
                        checked = (dt.hasClass('layui-this') || o.inArray(dt.attr('lay-value'), selds) > -1) ? 'checked' : '',
                        title = dt.text(),
                        disabled = dt.attr('lay-value') === '' ? 'disabled' : '';
                    dt.html('<input type="checkbox" lay-skin="primary" title="' + title + '" ' + checked + ' ' + disabled + '>');
                    ts.selected(idx, t, dt);
                }).click(function(e) {
                    var dt = o(this);
                    // 点击下拉框每一行触发选中和反选
                    if(e.target.localName == 'dd' && dt.attr('lay-value') !== '') {
                        var status = dt.find('.layui-form-checkbox').toggleClass('layui-form-checked').hasClass('layui-form-checked');
                        dt.find('input').prop('checked', status);
                    }
                    // 禁止下拉框收回
                    dt.parents('.layui-form-select').addClass('layui-form-selected');
                    ts.selected(idx, t, dt);
                });
            })
            form.render('checkbox');
        }

        multiSelect.prototype.selected = function(idx, t, dt) {
            // 选中值存入数组
            selected_vals[idx] = [];
            // 先清除真实下拉款选中的值，在下面循环中重新赋值选中
            t.find('option').prop('selected', false);
            dt.parents('dl').find('[type=checkbox]:checked').each(function() {
                var val = o(this).parent().attr('lay-value');
                t.find('option[value=' + val + ']').prop('selected', true);
                selected_vals[idx].push(o(this).attr('title'));
            })
            // 显示已选信息
            dt.parents('dl').prev().find('input').val(selected_vals[idx].join(','));
        }

        multiSelect.prototype.render = function(type, filter) {
            form.render(type, filter);
            this.init();
        }

        var i = new multiSelect();
        i.init();

        exports(MOD_NAME, i);
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
